package com.hzhc.controller.chargemanager;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.entity.ChargeConfig;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.ChargeConfigService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.ChargeConfigVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zhoumx
 * @date 2024/5/29
 * @description ChargeContractController 计费项配置
 */
@RestController
@RequestMapping("/chargeConfig")
@RequiredArgsConstructor
public class ChargeConfigController extends BaseController {

    private final ChargeConfigService configService;

    /**
     * 列表获取list（计费）
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/configList")
    @ResponseBody
    public ResultUtil<List<ChargeConfigVo>> configList(HttpServletRequest request,@RequestBody ChargeConfigVo vo ){
        Page<ChargeConfigVo> page=new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<ChargeConfigVo> configs = configService.selectChargeConfig(page,vo);
        return ResultUtil.build(configs,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }




    /**
     * 增加（计费）
     */
    @PostMapping("/addRet")
    @ResponseBody
    @SysTemLog(operModul = "计费管理-计费配置项增加", operType = "增加", operDesc = "计费配置项增加功能", modular="PC")
    public ResultUtil<T> addRet(HttpServletRequest request, @RequestBody ChargeConfig chargeConfig){
        Long userId= TokenUtil.getUserID(request);
//        chargeConfig.setUserId(chargeConfig.getId().longValue());
        chargeConfig.setUserId(userId);
        return configService.saveChargeConfig(chargeConfig);

    }

    /**
     * 删除(计费)
     */
    @PostMapping("/delChargeConfig/{id}")
    @SysTemLog(operModul = "计费管理-计费配置项删除", operType = "删除", operDesc = "计费配置项删除功能", modular="PC")
    public ResultUtil<T> deleteRet(@PathVariable("id") Long id) {
        Boolean b = configService.delChargeConfig(id);
        return b ? ResultUtil.ok() : ResultUtil.fail();
    }

    /**
     * 获取作业项配置列表
     */
    @RequestMapping("/workItemConfigList")
    @ResponseBody
    public ResultUtil<List<ChargeConfigVo>> workItemConfigList(HttpServletRequest request, @RequestBody ChargeConfigVo chargeConfigVo){
        Page<ChargeConfig> page=new Page<>(chargeConfigVo.getPageIndex(), chargeConfigVo.getPageSize());
        List<ChargeConfigVo> list=configService.selectWorkItemConfigList(page,chargeConfigVo);
        return ResultUtil.build(list,page.getTotal(),page.getSize(),ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 增加（作业）
     */
    @PostMapping("/addRetWorkItemConfig")
    @ResponseBody
    @SysTemLog(operModul = "计费管理-工作项配置项增加", operType = "增加", operDesc = "工作项项配置增加功能", modular="PC")
    public ResultUtil<T> addRetWorkItemConfig(HttpServletRequest request, @RequestBody ChargeConfig chargeConfig){
        Long userId= TokenUtil.getUserID(request);
        chargeConfig.setUserId(userId);
        return configService.saveWorkItemConfig(chargeConfig);

    }

    /**
     * 删除(工作项)
     */
    @PostMapping("/delWorkItemConfig/{id}")
    @SysTemLog(operModul = "计费管理-工作项配置删除", operType = "删除", operDesc = "工作项配置删除功能", modular="PC")
    public ResultUtil<T> delWorkItemConfig(@PathVariable("id") Long id) {
        Boolean b = configService.delChargeConfig(id);
        return b ? ResultUtil.ok() : ResultUtil.fail();
    }


    /**
     * check项目是否唯一
     */
    @PostMapping("/checkchargeItem")
    public ResultUtil<T> checkDict(@RequestBody ChargeConfig chargeConfig) {
        return configService.checkChargeItemField(chargeConfig);
    }

    /**
     * check作业项配置是否唯一
     */
    @PostMapping("/checkWorkItemId")
    public ResultUtil<T> checkWorkItemId(@RequestBody ChargeConfig chargeConfig) {
        return configService.checkWorkItemId(chargeConfig);
    }
}
